import request from './request'

export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface ProjectDoc {
  id: number
  projectId: number
  title: string
  content: string
  folderId?: string
  isShare: boolean
  tips: string
  createByName: string
  createdAt: string
  updatedAt: string
}

export interface CreateProjectDocRequest {
  projectId: number
  title: string
  content: string
  folderId?: string
  isShare?: boolean
  tips?: string
}

export interface UpdateProjectDocRequest {
  id: number
  title: string
  content: string
  folderId?: string
  isShare?: boolean
  tips?: string
}

export interface ProjectDocListParams {
  projectId: number
  tip?: string
  keyWord?: string
  isShare?: boolean
  pageDto: {
    pageNumber: number
    pageSize: number
  }
}

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  pageNumber: number
  pageSize: number
}

// 获取项目文档列表
export const getProjectDocList = (params: ProjectDocListParams): Promise<ApiResponse<PagedResult<ProjectDoc>>> => {
  return request.post('/projectDoc/getDocList', params)
}

// 获取文档详情
export const getProjectDocInfo = (id: number): Promise<ApiResponse<ProjectDoc>> => {
  return request.post('/projectDoc/getDocInfo', { id })
}

// 创建项目文档
export const createProjectDoc = (data: CreateProjectDocRequest): Promise<any> => {
  return request.post('/projectDoc/addDoc', data)
}

// 更新项目文档
export const updateProjectDoc = (data: UpdateProjectDocRequest): Promise<any> => {
  return request.post('/projectDoc/updateDoc', data)
}

// 删除项目文档
export const deleteProjectDoc = (id: number): Promise<any> => {
  return request.post('/projectDoc/delDoc', { id })
}

// 获取项目标签列表
export const getProjectDocTips = (projectId: number): Promise<ApiResponse<string[]>> => {
  return request.post('/projectDoc/getTips', { id: projectId })
}
